//查询交流记录
function queryRemarkByCustomId(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#remarkPage #pageNow').text();
		var pageCount = $('#remarkPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#remarkPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#remarkPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#remarkPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#remarkPage #pageCount').text();
	}
	var cusId = $('#customId').text();
	var url = rootPath + "/customerManage/queryCustomerRemark";

	$.post(
			url,
		{
			"cusId": cusId
		},
		function(data) {
			var json = eval(data);
			var html = "";
			html += "<tr>";
			html += 	"<th>联系人</th>";
			html += 	"<th>交流方式</th>";
			html += 	"<th>预约下次交流时间</th>";
			html += 	"<th>内容</th>";
			html += 	"<th>添加时间</th>";
			html += "</tr>";
			for(var i=0; i<json.length; i++) {
				html += "<tr>";
				html += 	'<td>' + json[i].cname + "</td>";
				if(json[i].talkMode!=null && json[i].talkMode!=0){
					if(json[i].talkMode==1){
						html += 	"<td>电话沟通</td>";
					}else if(json[i].talkMode==2){
						html += 	"<td>邮件</td>";
					} else if(json[i].talkMode==3){
						html += 	"<td>外出拜访</td>";
					} else if(json[i].talkMode==4) {
						html += 	"<td>公司会见</td>";
					} else {
						html += 	"<td></td>";
					}
					
				} else {
					html += 	"<td></td>";
				}
				html += 	'<td>' + json[i].nextTime + "</td>";
				html += 	'<td>' + json[i].remark + "</td>";
				html += 	'<td width="120">' + json[i].addTime + '</td>';
				html += "</tr>";
			}
		 
		 $('#remarkDiv #dataList').html(html);

		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#remarkPage #pageNow').val(pageNow);
			$('#remarkPage #pageSize').html("1-" + 50);
			$('#remarkPage #rowCount').html(rowCount);
			$('#remarkPage #pageNow').html(pageNow);
			$('#remarkPage #pageCount').html(pageCount);
		} else {
			$('#remarkPage #pageNow').val("1");
			$('#remarkPage #pageSize').html("1-50");
			$('#remarkPage #rowCount').html("0");
			$('#remarkPage #pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}

//查询交流记录
function queryContactByCustomId(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#contactPage #pageNow').text();
		var pageCount = $('#contactPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#contactPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#contactPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#contactPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#contactPage #pageCount').text();
	}
	var cusId = $('#customId').text();
	var url = rootPath + "/contact/queryContact";

	$.post(
			url,
		{
			"cusId": cusId
		},
		function(data) {
			var json = eval(data);
			var html = "";
			html += "<tr>";
			html += 	"<th>单位名称</th>";
			html += 	"<th>联系人</th>";
			html += 	"<th>性别</th>";
			html += 	"<th>移动电话</th>";
			html += 	"<th>固定电话</th>";
			html += 	"<th>QQ</th>";
			html += 	"<th>邮箱</th>";
			html += 	"<th>经营类型</th>";
			html += 	"<th>通讯地址</th>";
			html += 	"<th>是否决策人</th>";
			html += 	"<th>客户等级</th>";
			html += 	"<th>创建时间</th>";
			
			html += "</tr>";
			
			for(var i=0; i<json.length; i++) {
				html += "<tr>";
				html += 	'<td>' + json[i].uname + "</td>";
				html += 	'<td>' + json[i].cname + '</td>';
				if(json[i].sex!=null && json[i].sex!=0){
					if(json[i].sex==1){
						html += 	"<td>男</td>";
					}else {
						html += 	"<td>女</td>";
					}
					
				} else {
					html += 	"<td></td>";
				}
				html += 	'<td>' + json[i].mobile + '</td>';
				html += 	'<td>' + json[i].phone + "</td>";
				html += 	'<td>' + json[i].qq + '</td>';
				
				if(json[i].email!=null){
					html += 	'<td>' + json[i].email + '</td>';
				} else {
					html += 	'<td></td>';
				}
				
				if(json[i].managementType!=null && json[i].managementType!=0){
					if(json[i].managementType==1){
						html += 	"<td>国有</td>";
					}else if(json[i].managementType==2){
						html += 	"<td>民营</td>";
					} else if(json[i].managementType==3){
						html += 	"<td>个体</td>";
					} else if(json[i].managementType==4) {
						html += 	"<td>外资</td>";
					} else {
						html += 	"<td></td>";
					}
					
				} else {
					html += 	"<td></td>";
				}
				html += 	'<td>' + json[i].address + '</td>';
				if(json[i].isDecision!=null && json[i].isDecision!=0){
					if(json[i].isDecision==1){
						html += 	"<td>是</td>";
					}else {
						html += 	"<td>否</td>";
					}
					
				} else {
					html += 	"<td></td>";
				}
				
				if(json[i].grade!=null && json[i].grade!=0){
					
					html += 	'<td>' + json[i].grade + '</td>';
				} else {
					html += 	"<td></td>";
				}
				
				html += 	'<td>' + json[i].createTime + '</td>';
				html += "</tr>";
			}
		 
		 $('#contactDiv #dataList').html(html);

		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#orderPage #pageNow').val(pageNow);
			$('#orderPage #pageSize').html("1-" + pageSize);
			$('#orderPage #rowCount').html(rowCount);
			$('#orderPage #pageNow').html(pageNow);
			$('#orderPage #pageCount').html(pageCount);
		} else {
			$('#orderPage #pageNow').val("1");
			$('#pageSize').html("1-50");
			$('#orderPage #rowCount').html("0");
			$('#orderPage pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}

//查询相关订单
function queryOrderByCustomId(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#orderPage #pageNow').text();
		var pageCount = $('#orderPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#orderPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#orderPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#orderPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#orderPage #pageCount').text();
	}
	var customId = $('#customId').text();
	var url = rootPath + "/customerManage/queryOrderByCustomId";

	$.post(
			url,
		{
				"customId" : customId,
				"pageNow" : pageNow
		}, 
	function(data) {
			 var json = eval(data);
			 if(5 == json) {
				 
			 }
			 var html = "";
			 html += '<tr>';
			 html += '<th>订单编号</th>';
			 html += '<th>服务编号</th>';
			 html += '<th>商品名称</th>';
			 html += '<th>商品类型</th>';
			 html += '<th>类型</th>';
			 /*html += '<th>年限</th>';*/
			 html += '<th>订单价格</th>';
			 html += '<th>域名</th>';
			 html += '<th>订单日期</th>';
			 
			 html += '<th>服务开始时间</th>';
			 html += '<th>服务到期时间</th>';
			 html += '<th>是否退费</th>';
			 html += '</tr>';
			 for(var i=0; i<json.length; i++) {
				 html += '<tr>';
				 html += '<td>' + json[i].orderId + '</td>';
				 html += '<td>' + json[i].serviceId + '</td>';
				 html += '<td>' + json[i].goodsName + '</td>';
				 html += '<td>' + json[i].productName + '</td>';
				 html += '<td>' + json[i].orderType + '</td>';
				/* html += '<td>' + json[i].timeAmount +'' + json[i].timeUnit + '</td>';*/
				 html += '<td>' + json[i].goodsPrice + '/' + json[i].timeAmount +'' + json[i].timeUnit + '</td>';
				 html += '<td>' + json[i].domainName + '</td>';
				 
				 
				 if(null != json[i].operateTime) {
					 
					 html += '<td>' + json[i].operateTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 if(null != json[i].buyTime) {
					 
					 html += '<td>' + json[i].buyTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 if(null != json[i].dueTime) {
					 
					 html += '<td>' + json[i].dueTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 html += '<td>' + json[i].isReturns + '</td>';
				 html += '</tr>';
		}
		 
		 $('#orderDiv #dataList').html(html);

		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#orderPage #pageNow').val(pageNow);
			$('#orderPage #pageSize').html("1-" + pageSize);
			$('#orderPage #rowCount').html(rowCount);
			$('#orderPage #pageNow').html(pageNow);
			$('#orderPage #pageCount').html(pageCount);
		} else {
			$('#orderPage #pageNow').val("1");
			$('#pageSize').html("1-50");
			$('#orderPage #rowCount').html("0");
			$('#orderPage pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}

//查询购买商品
function queryBuyGoods(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#buyGoodsPage #pageNow').text();
		var pageCount = $('#buyGoodsPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#buyGoodsPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#buyGoodsPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#buyGoodsPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#buyGoodsPage #pageCount').text();
	}
	var customId = $('#customId').text();
	var url = rootPath + "/customerManage/queryBuyGoods";

	$.post(
			url,
		{
				"customId" : customId,
				"pageNow" : pageNow
		}, 
	function(data) {
			 var json = eval(data);
			 var html = "";
			 html += '<tr>';
			 html += '<th>商品名称</th>';
			 html += '<th>商品类型</th>';
			 html += '<th>服务编号</th>';
			 html += '<th>商品价格</th>';
			 html += '<th>域名</th>';
			 html += '<th>服务开始时间</th>';
			 html += '<th>服务到期时间</th>';
			 html += '</tr>';
			 for(var i=0; i<json.length; i++) {
				 html += '<tr>';
				 html += '<td>' + json[i].goodsName + '</td>';
				 html += '<td>' + json[i].productName + '</td>';
				 html += '<td>' + json[i].serviceId + '</td>';
				 html += '<td>' + json[i].goodsPrice + '</td>';
				 html += '<td>' + json[i].domainName + '</td>';
				 if(null != json[i].buyTime) {
					 
					 html += '<td>' + json[i].buyTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 if(null != json[i].dueTime) {
					 
					 html += '<td>' + json[i].dueTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				
				 html += '</tr>';
		}
		 
		 $('#buyGoodsDiv #dataList').html(html);

		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#buyGoodsPage #pageNow').val(pageNow);
			$('#buyGoodsPage #pageSize').html("1-" + pageSize);
			$('#buyGoodsPage #rowCount').html(rowCount);
			$('#buyGoodsPage #pageNow').html(pageNow);
			$('#buyGoodsPage #pageCount').html(pageCount);
		} else {
			$('#buyGoodsPage #pageNow').val("1");
			$('#pageSize').html("1-50");
			$('#buyGoodsPage #rowCount').html("0");
			$('#buyGoodsPage pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}


//查询购买商品
function queryShopCarts(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#shopingCarPage #pageNow').text();
		var pageCount = $('#shopingCarPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#shopingCarPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#shopingCarPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#shopingCarPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#shopingCarPage #pageCount').text();
	}
	var customId = $('#customId').text();
	var url = rootPath + "/cart/showInfo/"+pageNow;

	$.post(
			url,
		{
				"customId" : customId
		}, 
	function(data) {
			 var json = eval(data);
			 var html = "";
			 html += '<tr>';
			 html += '<th></th>';
			 html += '<th>会员编号</th>';
			 html += '<th>客户类型</th>';
			 html += '<th>联系人</th>';
			 html += '<th>手机</th>';
			 html += '<th>电子邮箱</th>';
			 html += '<th>所属人</th>';
			 html += '<th>所属区域</th>';
			 html += '</tr>';
			 if(json.length == 0) {
					html += '<tr><td colspan="9">没有查到相关数据！</td></tr>';
			 }else {
				 for(var i=0; i<json.length; i++) {
					 html += '<tr>';
					 //html += '<td> <a href="#" id="showCart'+json[i].customId +'" name="showCart" onclick="cartController(' + "'" + json[i].customId + "'," +"'" + json[i].empId + "',this)"+'">+</a></td>';
					 html += '<td> <a href="#" id="showCart" name="showCart" onclick="cartController(' + "'" + json[i].customId + "'," +"'" + json[i].empId + "',this)"+'">+</a></td>';
					 html += '<td>' + json[i].customId + '</td>';
					 html += '<td>' + json[i].customerTypeStr + '</td>';
					 html += '<td>' + json[i].customName + '</td>';
					 html += '<td>' + json[i].phone + '</td>';
					 html += '<td>' + json[i].email + '</td>';
					 html += '<td>' + json[i].empName + '</td>';
					 html += '<td>' + json[i].areaName + '</td>';
					
					 html += '</tr>';
					 
					 html += '<tr id="'+json[i].customId+json[i].empId+'cartFrame" style="display: none;height:auto;">';
					 html += '<td colspan="9"></td>';
					 html += '</tr>';
					 
				 	}
				 
		 
				
			 }
			 $('#shopingCarDiv #dataList').html(html);
		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#shopingCarPage #pageNow').val(pageNow);
			$('#shopingCarPage #pageSize').html("1-" + pageSize);
			$('#shopingCarPage #rowCount').html(rowCount);
			$('#shopingCarPage #pageNow').html(pageNow);
			$('#shopingCarPage #pageCount').html(pageCount);
		} else {
			$('#shopingCarPage #pageNow').val("1");
			$('#pageSize').html("1-50");
			$('#shopingCarPage #rowCount').html("0");
			$('#shopingCarPage pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}


/*
function cartController(id,code,hwnd) {
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();
	var showCart = "showCart";
	var hwndId = showCart+id;
	var label=$("#"+hwndId).text();
	var frame=$("#"+id+code+"cartFrame");
	if(label=="+") {
		$("#"+hwndId).text("-");
		$.ajax({
			type:"POST",
			dataType:"text",
			data:{"cusId":id},
			url:rootPath+"/cart/showCart/1",
			success:function(msg) {
				var td=frame.find("td");
				var iframe=$("<iframe id="+id+" style='overflow-x:auto ; width:100%;' src="+rootPath+"/cart/openCartPage></iframe>");
				td.append(iframe);
				frame.fadeIn(600);
			}
		});
	}
	else {
		$("#"+hwndId).text("+");
		frame.fadeOut(600);
	}
}*/

function cartController(id,code,hwnd) {
	var label=$(hwnd).text();
	rootPath = $('#rootPath').val();
	var frame=$("#"+id+code+"cartFrame");
	if(label=="+") {
		$(hwnd).text("-");
		$.ajax({
			type:"POST",
			dataType:"text",
			data:{"cusId":id},
			url:rootPath+"/cart/showCart/1",
			success:function(msg) {
				var td=frame.find("td");
				var iframe=$("<iframe id="+id+" style='overflow-x:auto ; width:100%;' src="+rootPath+"/cart/openCartPage></iframe>");
				td.append(iframe);
				frame.fadeIn(600);
			}
		});
	}
	else {
		$(hwnd).text("+");
		frame.fadeOut(600);
	}
}

//查询推送详情
function queryPushDetails(pageNow) {
	controllerWaitingBar(true);
	// 获取项目上下文路径
	rootPath = $('#rootPath').val();

	// 获取当前页的下一页/上一页
	if (!pageNow) {
		pageNow = 1;
	} else if (pageNow == "nextPage") {
		pageNow = $('#pushDetailsPage #pageNow').text();
		var pageCount = $('#pushDetailsPage #pageCount').text();
		// 如果当前页是最后一页 则下一页无效
		if (pageNow == pageCount) {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#pushDetailsPage #pageNow').text() * 1 + 1;
	} else if (pageNow == "prevPage") {
		pageNow = $('#pushDetailsPage #pageNow').text();
		// 如果当前页是第一页 则上一页无效
		if (pageNow == "1") {
			controllerWaitingBar(false);
			return;
		}
		pageNow = $('#pushDetailsPage #pageNow').text() * 1 - 1;
	} else if (pageNow == "lastPage") {
		pageNow = $('#pushDetailsPage #pageCount').text();
	}
	var customId = $('#customId').text();
	var url = rootPath + "/customerManage/queryPushDetails";

	$.post(
			url,
		{
				"customId" : customId,
				"pageNow" : pageNow
		}, 
	function(data) {
			 var json = eval(data);
			 var html = "";
			 html += '<tr>';
			 html += '<th>推送时间</th>';
			 html += '<th>流走时间</th>';
			 html += '<th>客户类型</th>';
			 html += '<th>推送人</th>';
			 html += '<th>接收人</th>';
			 html += '<th>推送商品</th>';
			 html += '<th>推送备注</th>';
			 html += '</tr>';
			 for(var i=0; i<json.length; i++) {
				 html += '<tr>';
				 html += '<td>' + json[i].startTime + '</td>';
				 if(null != json[i].endTime) {
					 
					 html += '<td>' + json[i].endTime + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 html += '<td>' + json[i].customerTypeStr + '</td>';
				 html += '<td>' + json[i].pusherName + '</td>';
				 html += '<td>' + json[i].ename + '</td>';
				 if(null != json[i].productName) {
					 
					 html += '<td>' + json[i].productName + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 if(null != json[i].pushDesc) {
					 
					 html += '<td>' + json[i].pushDesc + '</td>';
				 }else {
					 html += '<td></td>';
				 }
				 html += '</tr>';
		}
		 
		 $('#pushDetailsDiv #dataList').html(html);

		// 显示分页
		if (json.length) {
			var pageNow = json[0].pageNow;
			var pageSize = json[0].pageSize;
			var rowCount = json[0].rowCount;
			var pageCount = json[0].pageCount;

			$('#pushDetailsPage #pageNow').val(pageNow);
			$('#pushDetailsPage #pageSize').html("1-" + pageSize);
			$('#pushDetailsPage #rowCount').html(rowCount);
			$('#pushDetailsPage #pageNow').html(pageNow);
			$('#pushDetailsPage #pageCount').html(pageCount);
		} else {
			$('#pushDetailsPage #pageNow').val("1");
			$('#pageSize').html("1-50");
			$('#pushDetailsPage #rowCount').html("0");
			$('#pushDetailsPage pageCount').html("1");
		}
		controllerWaitingBar(false);
	});
}

//调到指定页面
function goPage(page) {
	
	var inputPage = '';
	if(1 == page) {
		inputPage = $('#orderDiv #inputPage').val();
	}
	
	if(2 == page) {
		inputPage = $('#buyGoodsDiv #inputPage').val();
	}
	
	if(3 == page) {
		inputPage = $('#pushDetailsDiv #inputPage').val();
	}
	
	var reg = /^[0-9]+$/;
	if(inputPage == "") {
		return ;
	}
	if(!reg.test(inputPage)) {
		alert("请输入正确的页数");
		return ;
	}
	
	if(1 == page) {
		queryOrder(inputPage);
	}
	
	if(2 == page) {
		queryBuyGoods(inputPage);
	}
	
	if(3 == page) {
		queryPushDetails(inputPage);
	}
	
	
}

//弹出添加记录窗口
function showAddContact(customerId) {
	$('#uname').val('');
	$('#cname1').val('');
	$("#sex option[value='0']").attr("selected","selected");
	$('#mobile').val('');
	$('#phone').val('');
	$('#qq').val('');
	$('#email').val('');
	$("#managementType option[value='0']").attr("selected","selected");
	$('#address').val('');
	$("#isDecision option[value='0']").attr("selected","selected");
	$("#grade option[value='0']").attr("selected","selected");
	$('#contactCustomerId').val(customerId);
	$('#addContact').show();
	$(".bg").fadeIn(100);
}

function doAddContact() {
	
	var uname = $('#uname').val();
	var cname = $('#cname1').val();
	var sex = $("#sex").val();
	var mobile = $('#mobile').val();
	var phone = $('#phone').val();
	var email = $('#email').val();
	var qq = $('#qq').val();
	var managementType = $("#managementType").val();
	var address = $('#address').val();
	var isDecision = $("#isDecision").val();
	var grade = $("#grade").val();
	var customerId = $('#customId').text();
	
	
	if(cname==null||cname==""){
		  alert("联系人名称不能为空");
	      controllerWaiting(false);
	      return;
	}
	
	if(cname==null||cname==""){
		  alert("联系人名称不能为空");
	      controllerWaiting(false);
	      return;
	}
	if(uname.length>50){
		  alert("单位名称过长");
	      controllerWaiting(false);
	      return;
	}
	
	if(cname.length>50){
		  alert("联系人名称过长");
	      controllerWaiting(false);
	      return;
	}
	
	if(qq.length>15){
		  alert("请填写正确的qq号码");
	      controllerWaiting(false);
	      return;
	}
	
	if(address.length>100){
		  alert("通讯地址过长");
	      controllerWaiting(false);
	      return;
	}
	
	//校验手机号和邮箱
	var re = /^1[3|5|7|8][0-9]\d{8}$/;
	
	var re2 = /^0\d{2,3}-?\d{7,8}$/;
	var re3 =/^(?:\w+\.?)*\w+@(?:\w+\.)*\w+$/;
	if (!re.test(mobile) ) {
        alert("请输入正确的手机号码");
        controllerWaiting(false);
        return;
    } 
	if (phone!=null&&phone!=""&& !re2.test(phone)) {
        alert("请输入正确的电话号码");
        controllerWaiting(false);
        return;
    } 
	
	
	if (email!=null&&email!=""&&!re3.test(email)) {
        alert("请输入正确的邮箱");
        controllerWaiting(false);
        return;
    } 
	
	$.post(
			getContextPath() + "/contact/addContact",
			{
				"cusId": customerId,
				"uname": uname,
				"cname": cname,
				"sex": sex,
				"mobile": mobile,
				"phone": phone,
				"qq": qq,
				"email":email,
				"managementType": managementType,
				"address": address,
				"isDecision": isDecision,
				"grade": grade
			},
			function(data) {
				$('#addContact').hide();
				alert(data);
				$(".bg").fadeOut(100);
				history.go(0);
				$('#contactDiv').show();
			}
		);
}

function initCartData(id) {
	$.ajax({
		type:"POST",
		dataType:"json",
		data:{"cusId":id},
		url:getContextPath()+"/cart/showCart/1",
		success:function(msg) {
			var data=eval(msg);
			var tab=$("#tab2");
//			tab.empty();
			for(var i=0;i<data.length;i++) {
				var tr=$("<tr></tr>");
				var td1=$("<td></td>");
				var td2=$("<td></td>");
				td1.text(data[i].productName);
				tr.append(td1);
				td2.text(data[i].addShopCartTime);
				tr.append(td2);
				tab.append(tr);
			}
		}
	});
}

function findAdminContact(customerId) {
	 
	$.ajax({
		type:"POST",
		data:{"cusId":customerId},
		url:"/contact/sysnContact",
		success:function(){
			location.reload();
		}
	});
}

function communicationMind(){
	var mind = $("#communicationMind").val();
	
	$("#mindDetail").hide();
	if(mind=0){
		$("#mindDetail").hide();
	}else{
		$("#mindDetail").show();
	}
}






